package demo.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * 演示返回JSON格式结果
 * 注解中produce参数表示返回的内容类型，标准参照HTTP content-type，见https://www.runoob.com/http/http-content-type.html
 * 其中“application/json”指JSON数据格式
 * PS.HTTP请求中也有content-type字段，规定了传入文件的格式
 *
 * json格式在返回体中可以以HashMap格式存在（会自动转换为json）
 */
@RestController
public class ControllerTest2 {
    @RequestMapping(value = "/returnJSON", produces = "application/json")
    public HashMap returnJSON(){
        HashMap accountHM = new HashMap();
        accountHM.put("id", "001");
        accountHM.put("name", "LiHua");
        accountHM.put("balance", "1000");
        return accountHM;
    }
}
